package cn.tangcent.rules;

import cn.tangcent.*;

import java.util.Arrays;

/**
 * Created by TangMing on 2017/4/8.
 * 规则:九宫中每个数字必出现一次
 * 如果九宫中某个数字只能出现在某格，则此格中数字可确定
 */
public class BlockRule extends PartitionRule {

    @Override
    public int selected(SudokuData sudokuData, int z) {
        return sudokuData.sz(z);
    }

    @Override
    public void check(SudokuData sudokuData, int z, int selected) {

        //收集空位
        Coordinate[] blanks = sudokuData.todos(SudokuUtils.entireBlock(z));
        Integer[] optionals = sudokuData.optionals(blanks);
        for (int i = 0; i < optionals.length; i++) {
            int finalI = i;
            SudokuUtils.forBit(optionals[i], o -> {
                setFlag(o, blanks[finalI]);
            });
        }
    }

}
